﻿using AutoMapper;
using DeviceDetectorNET;
using Microsoft.Extensions.Caching.Memory;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Domain.Services;
using Volo.Abp.Uow;
using YAKEJI.Abp.ChineseChar;
using YAKEJI.Abp.Domain.Repositories;
using YAKEJI.Xaf.DataDictionaries;
using YAKEJI.Xaf.Numbers;
using YAPACS.BusinessObjects.Exams;
using YAPACS.BusinessObjects.Managements.Devices;
using YAPACS.BusinessObjects.Managements.Exams;
using YAPACS.BusinessObjects.Managements.InterfaceServices;
using YAPACS.BusinessObjects.Managements.StoreServices;
using YAPACS.Organizations;
using YAPACS.RisServer.Abstractions;
using YAPACS.RisServer.Services.Dtos;
using YAPACS.RisServer.Workflows.ExamApply;
using YAPACS.Workflows;

namespace YAPACS.RisServer.Services;

public class ExamApplyService(IUnitOfWorkManager unitOfWorkManager, IRepository<Exam, Guid> examRepository,
    IRepository<ExamApplyItem, Guid> examApplyItemRepository, IRepository<InterfaceService, Guid> interfaceServiceRepository,
    IGetExamApply getExamApply, IGetAdvancedSearchView getAdvancedSearchView, IRepository<Department, Guid> departmentRepository,
    ICurrentUserOrganization currentUserOrganization, IRepository<Patient, Guid> patientRepository, IRepository<DataDictItem, Guid> dataDicItemRepository,
    IRepository<ApplyDoctor, Guid> applyDoctorRepository, IRepository<ApplyDepartment, Guid> applyDepartmentRepository,
    IRepository<ExamItem, Guid> examItemRepository, IRepository<PatientFrom, Guid> patientFromRepository, IRepository<DataDictionary, Guid> dataDictionaryRepository,
    IRepository<DeviceType, Guid> deviceTypeRepository, IExamEventService examEventService, IExamNumberService examNumberService, IMapper mapper,
    IGetHeaders getHeaders, IRegister register, IMemoryCache memoryCache, IHttpContextAccessor context, INumberService numberService,
    IChineseCharProvider chineseCharProvider, IExamPermissionService examPermissionService, IAccountVerifyService accountVerifyService)
    : DomainService, IExamApplyService, ITransientDependency
{
    private readonly IUnitOfWorkManager _unitOfWorkManager = unitOfWorkManager;
    private readonly IRepository<Exam, Guid> _examRepository = examRepository;
    private readonly IRepository<ExamApplyItem, Guid> _examApplyItemRepository = examApplyItemRepository;
    private readonly IRepository<Department, Guid> _departmentRepository = departmentRepository;
    private readonly ICurrentUserOrganization _currentUserOrganization = currentUserOrganization;
    private readonly IRepository<InterfaceService, Guid> _interfaceServiceRepository = interfaceServiceRepository;
    private readonly IRepository<Patient, Guid> _patientRepository = patientRepository;
    private readonly IRepository<DataDictionary, Guid> _dataDictionaryRepository = dataDictionaryRepository;
    private readonly IRepository<DataDictItem, Guid> _dataDicItemRepository = dataDicItemRepository;
    private readonly IRepository<ApplyDoctor, Guid> _applyDoctorRepository = applyDoctorRepository;
    private readonly IRepository<ApplyDepartment, Guid> _applyDepartmentRepository = applyDepartmentRepository;
    private readonly IRepository<ExamItem, Guid> _examItemRepository = examItemRepository;
    private readonly IRepository<PatientFrom, Guid> _patientFromRepository = patientFromRepository;
    private readonly IRepository<DeviceType, Guid> _deviceTypeRepository = deviceTypeRepository;
    private readonly IGetExamApply _getExamApply = getExamApply;
    private readonly IGetAdvancedSearchView _getAdvancedSearchView = getAdvancedSearchView;
    private readonly IExamEventService _examEventService = examEventService;
    private readonly IExamNumberService _examNumberService = examNumberService;
    private readonly IMapper _mapper = mapper;
    private readonly IGetHeaders _getHeaders = getHeaders;
    private readonly IRegister _register = register;

    private readonly IMemoryCache _memoryCache = memoryCache;
    private readonly string examApplyKey = context.HttpContext.Request.Headers["tempId"] + "-" + currentUserOrganization.UserId;

    private readonly INumberService _numberService = numberService;
    private readonly IChineseCharProvider _chineseCharProvider = chineseCharProvider;

    private readonly IExamPermissionService _examPermissionService = examPermissionService;
    private readonly IAccountVerifyService _accountVerifyService = accountVerifyService;

    private async Task<Patient> GetPatientAsync(ExamApplyDto examApply)
    {
        Patient patient = null;

        //根据身份证或者医保卡号或者其他凭证查询患者信息
        if (!(string.IsNullOrWhiteSpace(examApply.IdCardNumber) && string.IsNullOrWhiteSpace(examApply.MedicalInsuranceNumber)))
        {
            patient = await _patientRepository.FirstOrDefaultAsync(e =>
            (e.MedicalInsuranceType != null && e.MedicalInsuranceNumber == examApply.MedicalInsuranceNumber && e.MedicalInsuranceType.Code == examApply.MedicalInsuranceTypeCode)
            || (e.IdCardType != null && e.IdCardNumber == examApply.IdCardNumber && e.IdCardType.Code == examApply.IdCardTypeCode));
        }

        if (patient == null)
        {
            patient = await _patientRepository.NewEntityAsync();
            patient.PatientId = examApply.PatientId;
            patient.Name = examApply.Name;
            patient.NamePinYin = string.Join("", await _chineseCharProvider.GetPinYinAsync(patient.Name));
            patient.Sex = (PatientSex?)examApply.Sex;
            patient.BirthDate = examApply.BirthDate;
            patient.ParentName = examApply.ParentName;
            if (!string.IsNullOrWhiteSpace(examApply.IdCardTypeCode))
            {
                var dataDictionary = await _dataDictionaryRepository.FirstOrDefaultAsync(e => e.Name == "证件类型");
                if (dataDictionary != null)
                {
                    patient.IdCardType = await _dataDicItemRepository.FirstOrDefaultAsync(e => e.DataDictionary == dataDictionary && e.OuterCode == examApply.IdCardTypeCode);
                }
            }
            patient.IdCardNumber = examApply.IdCardNumber;
            if (!string.IsNullOrWhiteSpace(examApply.MedicalInsuranceTypeCode))
            {
                var dataDictionary = await _dataDictionaryRepository.FirstOrDefaultAsync(e => e.Name == "医保卡类型");
                if (dataDictionary != null)
                {
                    patient.MedicalInsuranceType = await _dataDicItemRepository.FirstOrDefaultAsync(e => e.DataDictionary == dataDictionary && e.OuterCode == examApply.MedicalInsuranceTypeCode);
                }
            }
            patient.MedicalInsuranceNumber = examApply.MedicalInsuranceNumber;
            patient.ElectronicHealthCode = examApply.ElectronicHealthCode;
            patient.PatientEMPI = examApply.PatientEMPI;
            patient.GlobalEMPI = examApply.GlobalEMPI;
            patient.PhoneNumber = examApply.PhoneNumber;
            patient.PhoneNumber2 = examApply.PhoneNumber2;
            patient.Address = examApply.Address;
            if (!string.IsNullOrWhiteSpace(examApply.EthnicGroupCode))
            {
                var dataDictionary = await _dataDictionaryRepository.FirstOrDefaultAsync(e => e.Name == "民族");
                if (dataDictionary != null)
                {
                    patient.EthnicGroup = await _dataDicItemRepository.FirstOrDefaultAsync(e => e.DataDictionary == dataDictionary && e.OuterCode == examApply.EthnicGroupCode);
                }
            }
        }

        return patient;
    }

    private async Task<ApplyDepartment> GetApplyDepartmentAsync(ExamApplyDto examApply, Institution institution)
    {
        var applyDepartment = await _applyDepartmentRepository.FirstOrDefaultAsync(e => e.OuterCode == examApply.ApplyDepartmentCode);
        if (applyDepartment == null)
        {
            applyDepartment = await _applyDepartmentRepository.NewEntityAsync();
            applyDepartment.OuterCode = examApply.ApplyDepartmentCode;
            applyDepartment.Name = examApply.ApplyDepartmentCode;
            applyDepartment.Institution = institution;
            applyDepartment.IsActive = true;
            applyDepartment.Code = await _numberService.GetNumberAsync(new NumberOptions
            {
                NumberId = typeof(ApplyDepartment).FullName,
                NumberTemplate = "D{0:<INDEX>,00000}",
            }, applyDepartment);
        }
        return applyDepartment;
    }

    private async Task<ApplyDoctor> GetApplyDoctorAsync(ExamApplyDto examApply, ApplyDepartment applyDepartment)
    {
        var applyDoctor = await _applyDoctorRepository.FirstOrDefaultAsync(e => e.OuterCode == examApply.ApplyDoctorCode);
        if (applyDoctor == null)
        {
            applyDoctor = await _applyDoctorRepository.NewEntityAsync();
            applyDoctor.OuterCode = examApply.ApplyDoctorCode;
            applyDoctor.Name = examApply.ApplyDoctorName;
            applyDoctor.Department = applyDepartment;
            applyDoctor.IsActive = true;
            applyDoctor.Code = await _numberService.GetNumberAsync(new NumberOptions
            {
                NumberId = typeof(ApplyDoctor).FullName,
                NumberTemplate = "T{0:<INDEX>,00000}",
            }, applyDoctor);
        }
        return applyDoctor;
    }

    private async Task<Exam> UpdateExamAsync(Exam exam, ExamApplyDto examApply)
    {
        //患者
        exam.Patient = await GetPatientAsync(examApply);
        //就诊卡号
        exam.MedicalCardNumber = examApply.MedicalCardNumber;
        //申请单号
        exam.ApplyNumber = examApply.ApplyNumber;
        //单据号
        exam.BillNumber = examApply.BillNumber;
        //发票号
        exam.InvoiceNumber = examApply.InvoiceNumber;
        //年龄
        exam.AgeValue = examApply.AgeValue;
        //年龄单位
        exam.AgeUnit = (AgeUnit?)examApply.AgeUnit;
        //身高
        exam.Height = examApply.Height;
        //体重
        exam.Weight = examApply.Weight;
        //患者来自
        if (!string.IsNullOrWhiteSpace(examApply.PatientFromCode))
        {
            exam.PatientFrom = await _patientFromRepository.FirstOrDefaultAsync(e => e.OuterCode == examApply.PatientFromCode);
        }
        //患者类型
        if (!string.IsNullOrWhiteSpace(examApply.PatientTypeCode))
        {
            var dataDictionary = await _dataDictionaryRepository.FirstOrDefaultAsync(e => e.Name == "患者类型");
            if (dataDictionary != null)
            {
                exam.PatientType = await _dataDicItemRepository.FirstOrDefaultAsync(e => e.DataDictionary == dataDictionary && e.OuterCode == examApply.PatientTypeCode);
            }
        }
        //病案号
        exam.MedicalRecordNumber = examApply.MedicalRecordNumber;
        //体检号
        exam.PhysicalExamNumber = examApply.PhysicalExamNumber;
        //门诊号
        exam.OutPatientNumber = examApply.OutPatientNumber;
        //住院号
        exam.InPatientNumber = examApply.InPatientNumber;
        //病区
        exam.InPatientArea = examApply.InPatientArea;
        //病房号
        exam.WardNumber = examApply.WardNumber;
        //床位号
        exam.BedNumber = examApply.BedNumber;
        //申请科室
        if (!string.IsNullOrWhiteSpace(examApply.ApplyDepartmentCode))
        {
            exam.ApplyDepartment = await GetApplyDepartmentAsync(examApply, exam.Department.Institution);
            //申请医生
            if (!string.IsNullOrWhiteSpace(examApply.ApplyDoctorCode))
            {
                exam.ApplyDoctor = await GetApplyDoctorAsync(examApply, exam.ApplyDepartment);
            }
        }
        //申请时间
        exam.ApplyTime = examApply.ApplyTime;
        //临床诊断
        exam.ClinicalDiagnosis = examApply.ClinicalDiagnosis;
        //现病史
        exam.MedicalHistory = examApply.MedicalHistory;
        //患者主诉
        exam.ChiefComplaint = examApply.ChiefComplaint;
        //过敏史
        exam.AllergyHistory = examApply.AllergyHistory;
        //从事职业
        if (!string.IsNullOrWhiteSpace(examApply.ProfessionCode))
        {
            var dataDictionary = await _dataDictionaryRepository.FirstOrDefaultAsync(e => e.Name == "从事职业");
            if (dataDictionary != null)
            {
                exam.Profession = await _dataDicItemRepository.FirstOrDefaultAsync(e => e.DataDictionary == dataDictionary && e.OuterCode == examApply.ProfessionCode);
            }
        }
        //婚姻状况
        if (!string.IsNullOrWhiteSpace(examApply.MaritalStatusCode))
        {
            var dataDictionary = await _dataDictionaryRepository.FirstOrDefaultAsync(e => e.Name == "婚姻状况");
            if (dataDictionary != null)
            {
                exam.MaritalStatus = await _dataDicItemRepository.FirstOrDefaultAsync(e => e.DataDictionary == dataDictionary && e.OuterCode == examApply.MaritalStatusCode);
            }
        }
        //月经史
        exam.MenstrualHistory = examApply.MenstrualHistory;
        //末次月经
        exam.LastMenstruationDate = examApply.LastMenstruationDate;
        //孕周
        exam.GestationalWeek = examApply.GestationalWeek;
        //预产期
        exam.ChildbirthDate = examApply.ChildbirthDate;
        //是否怀孕
        exam.IsPregnancy = examApply.IsPregnancy;
        //急诊患者
        if (!exam.IsEmergency)
        {
            exam.IsEmergency = examApply.IsEmergency;
        }
        //是否保密
        //是否缴费
        //备注
        exam.Remark = examApply.Remark;

        return exam;
    }
    private async Task<Exam> CreateOrUpdateExamAsync(ExamApplyDto examApply, Guid departmentId, Guid interfaceServiceId, Exam exam = null)
    {
        if (exam == null)
        {
            var department = await _departmentRepository.GetAsync(departmentId);
            exam = await _examRepository.NewEntityAsync();
            //科室
            exam.Department = department;
            //就诊凭证号
            //存储服务
            exam.StoreService = exam.Department.GetStoreService();
        }
        else
        {
            if (exam.ExamApplyItems.Count > 0)
            {
                exam.ExamApplyItems.RemoveAll(exam => true);
            }
        }
        var interfaceService = await _interfaceServiceRepository.GetAsync(interfaceServiceId);
        //接口服务
        exam.InterfaceService = interfaceService;
        await UpdateExamAsync(exam, examApply);
        return exam;
    }
    private async Task AddExamItemsAsync(Exam exam, IEnumerable<ExamApplyDto> examApplies)
    {
        var examItems = examApplies.Select(e => new
        {
            e.ExamItemCode,
            e.ExamItemName,
            e.ExamItemFee,
            e.ExamItemInsuranceCode,
            e.ExamItemStatus,
            e.ExamItemNumber
        }).ToList();

        var deviceType = examApplies.First().DeviceType;
        exam.ExamItems.DeleteObjectOnRemove=true;
        exam.ExamItems.RemoveAll(exam=>true);
        //检查项目
        foreach (var item in examItems)
        {
            if (!string.IsNullOrWhiteSpace(item.ExamItemCode))
            {
                var examItem = await _examItemRepository.FirstOrDefaultAsync(e => e.OuterCode == item.ExamItemCode);
                if (examItem == null)
                {
                    examItem = await _examItemRepository.NewEntityAsync();

                    examItem.OuterCode = item.ExamItemCode;
                    examItem.Name = item.ExamItemName;
                    examItem.IsActive = true;
                    examItem.Department = exam.Department;
                    examItem.Code = await _numberService.GetNumberAsync(new NumberOptions
                    {
                        NumberId = typeof(ExamItem).FullName,
                        NumberTemplate = "T{0:<INDEX>,00000}",
                    }, examItem);
                    //设备类型
                    examItem.DeviceType = await _deviceTypeRepository.FirstOrDefaultAsync(e => e.Code == deviceType) ?? throw new Exception($"未找到编码为【{deviceType}】的设备类型");
                    examItem.Fee = item.ExamItemFee;
                }
                exam.ExamItems.Add(examItem);
            }
        }

        if (exam.ExamItems.Count > 0)
        {
            exam.DeviceType = exam.ExamItems[0].DeviceType;
            exam.ExamFee = exam.ExamItems.Sum(e => e.Fee);
        }
    }

    private async Task AddExamApplyItemsAsync(Exam exam, IEnumerable<ExamApplyDto> examApplies)
    {
        foreach (var examApplyDto in examApplies)
        {
            var examApplyItem = await _examApplyItemRepository.NewEntityAsync();
            _mapper.Map(examApplyDto, examApplyItem);
            exam.ExamApplyItems.Add(examApplyItem);
        }
    }

    public async Task<WorkflowOutput> GetExamApplyItemsAsync(Guid interfaceServiceId, string number, DataGridRequest request)
    {
        try
        {
            var interfaceService = await _interfaceServiceRepository.GetAsync(interfaceServiceId);
            var input = new WorkflowInput {
                { "InterfaceService", interfaceService },
                { "Number",number},
                { "Input", request.UserData }
            };
            var columns = await _getHeaders.InvokeAsync([]);
            var workflowOutput = await _getExamApply.InvokeAsync(input);
            if (!workflowOutput.Success)
            {
                throw new Exception(workflowOutput.Error);
            }
            //var dataGrid = workflowOutput.Data.Serialize().Deserialize<DataGridDto>();
            if (workflowOutput.Data is DataGridDto dataGrid)
            {
                dataGrid.Columns = columns.Data;
                workflowOutput.Data = dataGrid;
                //缓存查询出来的数据
                if (_memoryCache.Get(examApplyKey) != null)
                {
                    _memoryCache.Remove(examApplyKey);
                }
                //设置过期时间
                _memoryCache.Set(examApplyKey, (List<ExamApplyDto>)(dataGrid.Rows), new MemoryCacheEntryOptions
                {
                    SlidingExpiration = TimeSpan.FromMinutes(30)
                });
            }

            //转换Dto            
            return workflowOutput;
        }
        catch (Exception ex)
        {
            Logger.LogException(ex);
            await _unitOfWorkManager.Current.RollbackAsync();
            return new WorkflowOutput
            {
                Success = false,
                Error = ex.Message
            };
        }
    }

    public async Task<WorkflowOutput> AddExamAsync(Guid interfaceServiceId, IList<string> examItemNumbers)
    {
        try
        {
            Guid examId = default;

            using (var uow = _unitOfWorkManager.Begin(requiresNew: true))
            {
                var examApplies = await VerifyAsync(examItemNumbers);
                var departmentId = _currentUserOrganization.DepartmentId.Value;
                var exam = await CreateOrUpdateExamAsync(examApplies[0], departmentId, interfaceServiceId);
                await AddExamApplyItemsAsync(exam, examApplies);
                await AddExamItemsAsync(exam, examApplies);
                await _examEventService.AddExamEventAsync(exam, "新建检查");
                await uow.CompleteAsync();
                examId = exam.Id;
            }

            using (var uow = _unitOfWorkManager.Begin(requiresNew: true))
            {
                var exam = await _examRepository.GetAsync(examId);
                await _examNumberService.SetNumberAsync(exam);
                var workflowOutput = await RegisterExamAsync(examItemNumbers, exam);
                await uow.CompleteAsync();
                return workflowOutput;
            }
        }
        catch (Exception ex)
        {
            Logger.LogException(ex);
            return new WorkflowOutput
            {
                Success = false,
                Error = ex.Message
            };
        }
    }

    public async Task<WorkflowOutput> GetAdvancedSearchViewAsync()
    {
        try
        {
            var workflowOutput = await _getAdvancedSearchView.InvokeAsync([]);
            return workflowOutput;
        }
        catch (Exception ex)
        {
            Logger.LogException(ex);
            await _unitOfWorkManager.Current.RollbackAsync();
            return new WorkflowOutput
            {
                Success = false,
                Error = ex.Message
            };
        }
    }

    public async Task<WorkflowOutput> SupplementaryAsync(Guid interfaceServiceId, Guid examId, IList<string> examItemNumbers)
    {
        try
        {
            List<ExamApplyDto> examApplies = await VerifyAsync(examItemNumbers);

            var exam = await _examRepository.GetAsync(examId);
            if (exam.Department.Oid != _currentUserOrganization.DepartmentId.Value)
            {
                throw new Exception($"{exam.AccessionNumber}不是本科室检查");
            }
            await CreateOrUpdateExamAsync(examApplies[0], exam.Department.Oid, interfaceServiceId, exam);
            await AddExamApplyItemsAsync(exam, examApplies);
            await AddExamItemsAsync(exam, examApplies);
            await _examEventService.AddExamEventAsync(exam, "同步补录");
            exam.ExamBodyPartiesText = string.Join(",", exam.ExamBodyParties.Select(m => m.GetShortName()).ToArray());
            exam.ExamMethodsText = string.Join(",", exam.ExamMethods.Select(m => m.GetShortName()).ToArray());
            exam.PatientFeaturesText = string.Join(",", exam.PatientFeatures.Select(m => m.GetShortName()).ToArray());
            exam.ExamItemsText = string.Join(",", exam.ExamItems.Select(m => m.GetShortName()).ToArray());
            exam.UpdateShared();
            var workflowOutput = await RegisterExamAsync(examItemNumbers, exam);

            return workflowOutput;
        }
        catch (Exception ex)
        {
            Logger.LogException(ex);
            await _unitOfWorkManager.Current.RollbackAsync();
            return new WorkflowOutput
            {
                Success = false,
                Error = ex.Message
            };
        }
    }

    private async Task<List<ExamApplyDto>> VerifyAsync(IList<string> examItemNumbers)
    {
        List<ExamApplyDto> examApplies = [];
        if (examItemNumbers.Count == 0) throw new Exception("未选择任何检查项目");

        if (_memoryCache.TryGetValue(examApplyKey, out List<ExamApplyDto> value))
        {
            examApplies = value.Where(e => examItemNumbers.Contains(e.ExamItemNumber)).ToList();
        }

        if (examApplies.GroupBy(a => $"{a.ParentName}-{a.Sex}-{a.AgeValue}-{a.AgeUnit}-{a.IdCardNumber}").Count() > 1)
        {
            throw new Exception($"检查项目中不能包含不同的患者");
        }

        if (examApplies.GroupBy(a => $"{a.DeviceType}").Count() > 1)
        {
            throw new Exception($"检查项目中不能包含不同的设备类型");
        }

        // ExamItemNumber必须有值
        if (examApplies.Any(e => string.IsNullOrWhiteSpace(e.ExamItemNumber)))
        {
            throw new Exception($"存在检查项目编号为空的项目");
        }

        if (examApplies.GroupBy(e => new { e.Name, e.Sex }).Count() > 1)
        {
            throw new Exception($"所选择的检查项目中存在不同的患者");
        }

        foreach (var examApplyDto in examApplies)
        {
            var examApplyItem = await _examApplyItemRepository.FirstOrDefaultAsync(e => e.ExamItemNumber == examApplyDto.ExamItemNumber);
            if (examApplyItem != null) throw new Exception($"【{examApplyDto.ExamItemName}({examApplyDto.ExamItemNumber})】检查项目已被使用");
        }

        return examApplies;
    }

    private async Task<WorkflowOutput> RegisterExamAsync(IList<string> examItemNumbers, Exam exam)
    {
        //回调函数,更新His状态
        var input = new WorkflowInput
            {
                { "ExamItemNumbers", examItemNumbers }
            };

        var workflowOutput = await _register.InvokeAsync(input);
        if (!workflowOutput.Success)
        {
            throw new Exception(workflowOutput.Error);
        }

        workflowOutput.Data = exam.Oid;
        _memoryCache.Remove(examApplyKey);

        return workflowOutput;
    }

    public async Task<WorkflowOutput> GetSupplementaryVerifyViewAsync(WorkflowInput input, string nextApi = null)
    {
        try
        {
            var examId = Guid.Parse(input.GetValueOrDefault("examId")?.ToString());
            var exam = await _examRepository.GetAsync(examId);
            await _examPermissionService.ValidateAsync(exam);
            var userName = input.GetValueOrDefault("userName")?.ToString();
            var password = input.GetValueOrDefault("password")?.ToString();
            if (string.IsNullOrWhiteSpace(userName))
            {
                var workflowOutput = await _accountVerifyService.GetVerifyViewAsync();
                if (!string.IsNullOrWhiteSpace(nextApi))
                {
                    workflowOutput.NextApi = nextApi;
                }
                return workflowOutput;
            }
            else
            {
                var workflowOutput = await _accountVerifyService.VerifyAsync(userName, password, "登记_同步补录", exam);
                workflowOutput.Info = "null";
                return workflowOutput;
            }
        }
        catch (Exception ex)
        {
            Logger.LogException(ex);
            await _unitOfWorkManager.Current.RollbackAsync();
            return new WorkflowOutput
            {
                Success = false,
                Error = ex.Message
            };
        }
    }
}
